//! \file spinlock.hpp
//! \brief Purewell Library SpinLock Header
//! \author Yubin Lim (purewell@gmail.com)
//! \since 2009-12-10

#ifndef __PWHDR_MUTEX_HPP__
#define __PWHDR_MUTEX_HPP__

#include "types.hpp"
#include "lockobject.hpp"

namespace purewell
{

//! \brief SpinLock
class PWAPI PWSpinLock : public PWLockObject
{
public:

	//! \brief Lock.
	void lock(void);

	//! \brief Lock test.
	//! If unlocking state, lock.
	//! \return On success, true.
	bool lockTest(void);

	//! \brief Lock test(time limited).
	//! If unlocked state, wait for unlocking and try to lock.
	//! \return On success, true.
	bool lockTimeLimit(size_t msec);

	//! \brief Unlock.
	void unlock(void);

public:
	//! \brief Create spinlock.
	//! \param[in] pshared Process shared lock.
	//! \return On success, spinlock pointer or NULL.
	static PWSpinLock* create(bool pshared);

	//! \brief Release spinlock object.
	//! \param[in] lock SpinLock object pointer.
	static void release(PWSpinLock* lock);

private:
	explicit PWSpinLock();
	virtual ~PWSpinLock();
};

};//namespace purewell

#endif//!__PWHDR_MUTEX_HPP__

